//
//  HJVideoModel.m
//  project
//
//  Created by yefei on 2019/7/20.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJVideoModel.h"
#import "HJUserManager.h"

@implementation HJVideoModel

- (NSString *)description {
    return [self yy_modelDescription];
}

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{@"files":[HJPlayerVideoDataSourceModel class]};//, @"user":[HJUserModel class]
}

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    [self transformProperties];
    
    return YES;
}

- (void)transformProperties {
    // 是否是视频,如果为空 则什么都不做
    if (self.files && self.files.count > 0) {
        HJPlayerVideoDataSourceModel *model = self.files.firstObject;
        self.isVideo = [model.fileType isEqualToString:@"video"];
        if (self.isVideo) {
            self.videoSource = model;
        } else {
            NSMutableArray<NSString *> *images = [NSMutableArray arrayWithCapacity:self.files.count];
            for (HJPlayerVideoDataSourceModel *imageModel in self.files) {
                [images addObject:imageModel.url];
            }
            self.imagesSource = images.mutableCopy;
        }
    }
}

@end


@implementation HJPlayerVideoDataSourceModel

- (NSString *)description {
    return [self yy_modelDescription];
}

@end


@implementation HJCommentModel

- (NSString *)description {
    return [self yy_modelDescription];
}

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{@"reviewList":[HJCommentModel class]};
}
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    [self transformProperties];
    
    return YES;
}

- (void)transformProperties {
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
    //调整行间距
    paragraphStyle.lineSpacing = 2;
    NSDictionary *attriDict = @{NSParagraphStyleAttributeName:paragraphStyle,
                                NSKernAttributeName:@(1),
                                NSFontAttributeName:[UIFont fontWithName:PingFangSC_Medium size:15]};
    NSMutableAttributedString *attributeText = [[NSMutableAttributedString alloc] initWithString:self.content attributes:attriDict];
    CGSize titleSize = [attributeText boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 112, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin) context:nil].size;
    self.cellHeight = titleSize.height+65;
    self.contentAttribute = attributeText;
    
    CGFloat replyTableHeight = self.cellHeight;
    if (self.reviewList.count>0) {
        for (HJCommentModel *model in self.reviewList) {
            replyTableHeight = replyTableHeight + model.cellHeight;
        }
        self.replyHeight = replyTableHeight;
    }
//     LKLog(@"cellHeight=%lf",replyTableHeight);
}

@end
